package com.minyifang.wcspf.work.ui.user.presenter;

import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.work.ui.user.view.ComplainView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LuoYaWei on 2018/9/4.
 */
public class ComplainPresenter extends BasePresenter<ComplainView> {
    public void commitComplain(String content, int type) {
        getView().showLoadingView();
        Map<String, Object> map = new HashMap<>();
        map.put("des", content);
        map.put("type", type);
        JSONObject jsonData = Constants.getJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().commitComplain(requestBody), respond -> {
            getView().hideLoadingView();
            if (respond.result == 1) {
                getView().showComplainRes(respond);
            } else
                getView().showRequestFailed(respond.message);
        });
    }
}
